#pragma once

#include "rs485_v3.hpp"
#include "agile_modbus_rtu_master.hpp"

class pwm_board
{
private:
    uint8_t _id;
    rs485_v3 *_rs485;
    agile_modbus_rtu_master_simple *_modbus;

    uint8_t _led_mode;
    uint8_t _led_brightness;
    uint32_t _led_color;

    yj_return _rs485_flag;

public:
    typedef enum
    {
        led_mode_on = 0x00,
        led_mode_blink_fast = 0x01,
        led_mode_blink_slow = 0x02,
    } led_mode_en;

    typedef enum
    {
        led_color_red = 0xFF0000,
        led_color_green = 0x00FF00,
        led_color_blue = 0x0000FF,
        led_color_yellow = 0xFFFF00,
        led_color_cyan = 0x00FFFF,
        led_color_purple = 0xFF00FF,
        led_color_white = 0xFFFFFF,
        led_color_black = 0x000000,
    } led_color_en;


    inline yj_return _read_reg(uint32_t reg_addr, std::vector<uint16_t> &reg_data);

public:
    pwm_board(uint8_t id, rs485_v3 *rs485, agile_modbus_rtu_master_simple *modbus);
    ~pwm_board(){};

    yj_return read_channel(uint8_t channel, uint8_t &value); // value 单位 0-100 对应舵机 0-100%行程
    yj_return write_channel(uint8_t channel, uint8_t value); // value 单位 0-100 对应舵机 0-100%行程

    yj_return set_led(led_color_en color,uint8_t brightness, led_mode_en mode); // 设置LED颜色和模式 亮度0-255
    yj_return set_led_brightness(uint8_t brightness); // 设置LED亮度 0-255
    yj_return set_led_mode(led_mode_en mode); // 设置LED模式
    yj_return set_led_color(led_color_en color); // 设置LED颜色

};